namespace Eco.Contrib.Demo
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Windows.Forms;
    using Eco.Contrib.Demo.EcoSpace;
    using Eco.Contrib.Demo.Model;
    using Eco.Handles;
    using Eco.Linq;
    using Eco.ObjectRepresentation;
    using Eco.Services;
    using Eco.UmlRt;
    using Eco.Windows.Forms;
    using Eco.WinForm;
    using Eco.Support;

    /// <summary>
    /// Summary description for Demo.
    /// </summary>
    public partial class WinDemo : System.Windows.Forms.Form
    {
        public WinDemo(EcoContribDemoEcoSpace ecoSpace)
        {
            // Required for Windows Form Designer support
            this.InitializeComponent();

            // Set EcoSpace (actually stores it in rhRoot.EcoSpace)
            // Note that you need to set the EcoSpace property for 
            // each ReferenceHandle and VariableHandle you add to 
            // the form.
            this.rhRoot.EcoSpace = ecoSpace;
        }

        public EcoContribDemoEcoSpace EcoSpace
        {
            get
            {
                return (EcoContribDemoEcoSpace)this.rhRoot.EcoSpace;
            }
        }

        private void btnDetails_Click(object sender, EventArgs e)
        {
            WinScript winDetail = new WinScript(EcoSpace, currencyManagerHandle1);
            winDetail.ShowDialog();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            //Script script = currencyManagerHandle1.Element.GetValue<Script>();
            //bool b = script.AttributeValueChanged("Name");
            //script.Name = "Hallo";
            //b = script.AttributeValueChanged("Name");
            //string sName = script.FetchedValue("Name") as string;
            //b = script.IsDirty();
            // script.Class2.Class1.Class2.AsIObjectList.Save();

            IEcoScriptLanguageService ESL = EcoSpace.GetEcoService<IEcoScriptLanguageService>();

            foreach (var script in from s in EcoSpace.MemQuery<Script>() select s)
            {
                ESL.RegisterScript(script.Name, script.Program, script.Parameter);
            }

            ESL.Execute((currencyManagerHandle1.Element.AsObject as Script).Name);
        }
    }
}
